package com.JustTest;

import com.google.common.io.PatternFilenameFilter;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;

/**
 * Created by mike on 18/5/16.
 */
public class FileReaderMain {
    public static void main(String[] args) throws Exception {
        String path = "/Users/mike/Downloads/test";
        File file = new File(path);
        if (file.isDirectory()) {
            FilenameFilter filenameFilter = new PatternFilenameFilter(".*\\.txt");
            File[] files = file.listFiles(filenameFilter);
            for (File filetmp : files) {
                boolean flag = false;
                int lineNum = 1;
                int flatNum = 1;
                int roomNum = 0;
                BufferedReader fileReader = new BufferedReader(new FileReader(filetmp));
                while (true) {
                    String line = fileReader.readLine();
                    if (line != null) {
                        if (line.split(";").length == 3) {
                            flag = true;
                        }
                        if (flag) {
                            roomNum++;
                            if (line.split(";").length >= 5) {
                                flatNum++;
                            }
                        }
                    } else {
                        break;
                    }
                    lineNum++;
                }
                System.out.println(filetmp.getName() + " 楼栋数：" + flatNum + "  房间数：" + roomNum);
            }
        }
    }
}
